import axios from "axios";
import React, { useEffect, useState } from "react";
import { Cell } from "react-vant";
import { useNavigate } from "react-router-dom";
const Index: React.FC = () => {
  const [list, setList] = useState<any>([]);
  const navigate = useNavigate();
  useEffect(() => {
    axios.get("/api/city").then((resp) => {
      setList(resp.data.city);
    });
  }, []);
  const cs = (i: any) => {
    localStorage.setItem("address", list[i].city);
    navigate("/home/my");
  };
  return (
    <div>
      {list.length > 0 &&
        list.map((v: any, i: any) => (
          <Cell title={v.city} key={i} onClick={() => cs(i)} />
        ))}
    </div>
  );
};
export default Index;
